package com.itlong.cloud.POJO.VO.property;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <desc>
 *      访客列表VO
 * </desc>
 *
 * @createDate 2018/06/28
 */

@Data
@NoArgsConstructor
public class PropertyVisitorInfoVO {

    private String passId;                  //访客密码id
    private String intervieweeName;         //受访人姓名
    private String visitorName;             //访客姓名
    private String visitorPhone;            //访客手机
    private String address;                 //使用地址
    private String isExpired;               //是否过期 1未过期 2已过期
    private Integer source;                 //数据来源 1APP 2物业
    private String sourceName;              //数据来源名称
    private String effectiveTime;           //有效时间
    private String operator;                //操作人
    private String createTime;              //创建时间
    private Integer sendMessageCount;       //已发送短信的次数
    private String roomId;                  //房间ID
    private String unitId;                  //单元ID
    private String idcardKey;               //身份证序号

    private String startTime;               //有效起始时间
    private String endTime;                 //有效结束时间

    private Integer checkStatus;            //物业审核状态 0代表未审批 1代表审批通过 2代表审批拒绝
    private String checkOperator = "系统";           //物业审批人员
    private String checkTime;               //物业审批时间
    private String passNumber;              //访客单号
    private Integer ownerCheckStatus;       //业主审核状态 0代表未审批 1代表审批通过 2代表审批拒绝
    private String ownerCheckTime;          //业主审批时间
    private String visitorTime;

    //人脸头像地址
    private String facePicUrl;

    public String getIsExpired() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        if (StringUtils.isEmpty(String.valueOf(startTime)) && StringUtils.isEmpty(String.valueOf(endTime))) {
            return "";
        }else{
            try {
                Date startDate = df.parse(startTime);
                Date endDate = df.parse(endTime);
                Date nowDate = df.parse(df.format(new Date()));
                if((nowDate.getTime()>=startDate.getTime()) && (nowDate.getTime()<=endDate.getTime()) ){
                    return "未过期";
                }else if(nowDate.getTime()<startDate.getTime()){
                    return "未过期";
                } else{
                    return "已过期";
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }

        }
        return "";
    }

    public String getSourceName() {
        if (source == null) {
            return "";
        }else{
            if(source==1){
                return "APP";
            }
            if(source==2){
                return "物业";
            }
        }
        return "";
    }

    public String getEffectiveTime(){
        if (StringUtils.isEmpty(String.valueOf(startTime)) && StringUtils.isEmpty(String.valueOf(endTime))) {
            return "";
        }else{
            return startTime+"-"+endTime;
        }
    }

}